#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
#include"lianjie.h"
int getsock(char *ip, char *dk) {
    //创建套接字
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1) {
        perror("socket");
        return -1;
    }

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(atoi(dk));
    inet_aton(ip, &addr.sin_addr);
    //连接服务端
    int jc =connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
    if (jc == -1) {
        perror("connect");
        return -1;
    }
    printf("成功接入！\n");
    return sockfd;
}

